// 创建一个SegmentView实例
var do_App = sm("do_App");
var do_Page = sm("do_Page");
var nf = sm("do_Notification");
var hashdata = mm("do_HashData");
var helperOpen = require("helper/open");
var helperCommunity = require("helper/community");

// UI
var rootview = ui("$");

do_Page.on("back", function() {
	do_App.closePage();
})

/** **************处理页面-头部-begin**************** */
var headerAout = ui("headerAout");
var addheader = headerAout.add("header", "source://view/reuse/header.ui", 0, 0);
// 左上角-返回
ui(addheader + ".headerLeft").on("touch", function() {
	do_App.closePage()
});
// 右上角-
var headerRight = ui(addheader + ".headerRight");
// 右上角添加+图标
var imgNext = ui(addheader + ".imgNext");
imgNext.source = "source://image/common/more.png";
imgNext.visible = true;
// 头部标题
var header = ui("header");
header.bindData(hashdata);
hashdata.addData({
	"labelTitle" : "我的活动"
});
header.refreshData();

var menus = [ {
	"template" : 0,
	"menuIcon" : "source://image/menu/activity.png",
	"menuName" : "发布活动",
	"type" : "addActivity"
}];
;
/*
 * 菜单弹出
 */
var popmenu = rootview.add("menupop", "source://view/reuse/menu/menu.ui", 0, 0);
var popmenuf = ui("menupop");
headerRight.on("touch", function() {
	popmenuf.fire("popmenuSJ", menus);
});

popmenuf.on("popmenuItem", function(data) {
	popmenuf.fire("popmenuClose");// 关闭菜单
	var touchIndex = parseInt(data);
	var actionType = menus[touchIndex].type;
	if (actionType == "addActivity") {// 发布活动
		helperOpen.open("source://view/activity/add/circle/mainNew.ui");
	} 
});
/** **************处理页面-头部-end**************** */
var viewShower = ui("viewShower");
var topIndex = 0;
var topAout0 = ui("aLayoutTop0");
var topAout1 = ui("aLayoutTop1");
var topAout = [ topAout0, topAout1];

var labelTop0 = ui("labelTop0");
var labelTop1 = ui("labelTop1");
var topLabel = [ labelTop0, labelTop1];

var labelLine0 = ui("labelLine0");
var labelLine1 = ui("labelLine1");
var labelLine = [ labelLine0, labelLine1];

var showIndex = 0
topAout.forEach(function(foot, tabIndex) {
	foot.on("touch", function(data, e) {
		if (topIndex !== tabIndex) {
			topLabel[topIndex].fontColor = "949EAAFF";
			labelLine[topIndex].bgColor = "00000000";
			topLabel[tabIndex].fontColor = "FF7E00FF";
			labelLine[tabIndex].bgColor = "FF7E00FF";
			showIndex = tabIndex;
			viewShower.showView("main" + tabIndex);
			fire2reflashData(tabIndex);
		}
		topIndex = tabIndex;
	});
});

var mains = [ {
	"id" : "main0",
	"path" : "source://view/activity/manage/create.ui"
}, {
	"id" : "main1",
	"path" : "source://view/activity/manage/sign.ui"
}];
viewShower.addViews(mains);
viewShower.showView("main" + showIndex);

do_Page.on("result", function(data) {
	fire2reflashData(showIndex);
});
/**
 * 刷新对应页面的数据
 * @param type
 */
function fire2reflashData(index){
	if (index == 0) {// 我创建的活动
		do_Page.fire("manage_activity_create_tab_touch", index);
	} else if (index == 1) {// 我加入的活动
		do_Page.fire("manage_activity_sign_tab_touch", index);
	}
}